<%@ page contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="/WEB-INF/tld/mytaglibs.tld" prefix="my"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html class="w99b h99b over_auto">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta http-equiv="Expires" content="0">
<%@ include file="/WEB-INF/views/common/jsinclude.jsp" %>
<title>客户</title>
<script type="text/javascript" charset="utf-8">
var mygrid;
var pager;
$(document).ready(function(){
	var gridTableHeight = $('#idGrid').height();
	$('#gridbox').height(gridTableHeight-DHTMLX_HEIGHT_OFF_FOOTER);
});
$(window).load(function() {
	fnLoad();
});


function fnLoad(){
<my:grid varGrid="mygrid" idGrid="gridbox" name="EntityCustomerGrid" splitAt="3" sort="true">
<my:gridevent varGrid="mygrid" eventName="onRowSelect" eventMethod="doOnRowSelected" />
</my:grid>
	pager=new PagerView("idPager",mygrid,30);
	pager.createDivPage();
	pager.onPageChanged = function(nextPage){
		setButtonStatus(true);
		search(nextPage,pager.pageSize);
	};
	pager.onGoClicked = function(pageNo,pageSize){
		setButtonStatus(true);
		search(pageNo,pageSize);
	};
	query();
}
function doOnRowSelected(id){
	setButtonStatus(false);
}
function fnGridFinish(){
	setButtonStatus(true);
	pager.showDivPageDhtmx();
	var vError=mygrid.getUserData("", "error");
	if(vError){
		alert("错误:"+vError);
	}
}
function setButtonStatus(theFlag){
	var viewButton = document.getElementById("idView");
    var editButton = document.getElementById("idEdit");
    var deleteButton = document.getElementById("idRemove");
    if(viewButton) viewButton.disabled = theFlag;
    if(editButton) editButton.disabled = theFlag;
    if(deleteButton) deleteButton.disabled = theFlag;
}
function create(){
 	var tmpURL = "${ctx}/entityCustomer/add.do";
    window.location.href=tmpURL;
}
function view(){
	var tmpKey = mygrid.getUserData(mygrid.getSelectedId(), "key");
    if(tmpKey == ""){
        alert("请选择要查看的数据!");
        return;
    }    
    var tmpURL = "${ctx}/entityCustomer/view.do?key="+tmpKey;
    window.location.href=tmpURL;
}
function remove(){   
	var tmpKey = mygrid.getUserData(mygrid.getSelectedId(), "key");
	if (tmpKey == null || tmpKey == "") {
		alert("请选择要删除的数据!");
		return;
	}
    if(confirm("警告:确定要删除此条记录?")){
		$.ajax({
    		async : false,
    		type : "post",
    		url : "${ctx}/entityCustomer/remove.do",
    		data : {
    			key : tmpKey
    		},
    		error : function() {
    			//alert("错误:请求服务响应失败!");
    		},
    		success : function(data) {
    			if (data == "success") {
    				var currentPage = getCurrentPage(mygrid);
    				var pageSize = getPageSize(mygrid);
    				search(currentPage, pageSize);
    			} else {
					alert(text);
				}
    		}
    	});
    }
}
function edit(){
	var tmpKey = mygrid.getUserData(mygrid.getSelectedId(), "key");
	if (tmpKey == null || tmpKey == "") {
		alert("请选择要修改的数据!");
		return;
	}
	var tmpURL = "${ctx}/entityOne/update.do?key=" + tmpKey;
	window.location.href = tmpURL;
}
function search(thePageNo,thePageSize,theStyle){
	var qryUrl = "${ctx}/entityCustomer/datagrid.do";
	qryUrl+="?prepend=where";
	qryUrl+="&qrySortFields=k_entitycustomer.custid";
	qryUrl+="&qrySortType=DESC";
	qryUrl+="&qryParamNames=pName|pCode|pShortname";
qryUrl+="&qryLogicFields=k_entitycustomer.custname|k_entitycustomer.custcode|k_entitycustomer.shortname";
qryUrl+="&qryFieldTypes=str|str|str";
qryUrl+="&qryOperators=like|like|like";
qryUrl+="&pName="+encodeValue(formQuery.pName.value);
qryUrl+="&pCode="+encodeValue(formQuery.pCode.value);
qryUrl+="&pShortname="+encodeValue(formQuery.pShortname.value);
	qryUrl+="&pagesize="+thePageSize;
	qryUrl+="&pageno="+thePageNo;
	if(theStyle == "excel"){
		qryUrl += "&pagestyle=excel";
		window.location.href=qryUrl;
	}
	else{
		mygrid.clearAll();
		mygrid.loadXML(qryUrl,fnGridFinish);
	}
}
function query(theStyle){
	if(pager.divPageFlag){
		search(1,pager.pageSize,theStyle);
	}
	else {
		search(-1,-1,theStyle);
	}
}
function fnExcel(){
	if(pager.divPageFlag){
		search(1,pager.pageSize,"excel");
	}
	else {
		search(-1,-1,"excel");
	}
}
</script>
</head>
<body id="idBody" class="w100b h100b">
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0">
<tr height="20px" id="idTop"><td nowrap>
<div class="page_header clearfix">
<span class="page_header_title">客户</span><span class="page_header_number_box">(<span class="page_header_number">5</span>)</span>
<span class="page_header_action_box">[管理]</span>
</div>
<div class="hr_title"></div>
<div class="form_area">
<form name="formQuery" action="" method="POST" >
<table border="0" cellspacing="5" cellpadding="0" width="100%">
<tr>
<td class="tdLabel" width="1%" nowrap>客户名称</td>
<td class="tdField" width="30%" nowrap><input type="text" size="18" name="pName" value="" class="inputSearchTxt"></td>
<td class="tdLabel" width="1%" nowrap>客户编码</td>
<td class="tdField" width="30%" nowrap><input type="text" size="18" name="pCode" value="" class="inputSearchTxt"></td>
<td class="tdLabel" width="1%" nowrap>客户简称</td>
<td class="tdField" width="30%" nowrap><input type="text" size="18" name="pShortname" value="" class="inputSearchTxt"></td>
<td class="tdField" nowrap align="right" colspan="8"> 
<input title="Search [Alt+Q]" accessKey="Q" class="query_button" type="button" name="btnSearch" value="查询" onclick="query()" />
<input title="Clear [Alt+C]"  accessKey="C" class="query_button" type="reset"  name="btnClear"  value="清空"/>
</td>
</tr>
</table>
</form>
</div>
<div class="hr_heng"></div>
<div class="margin_b_5 margin_t_2 align_left">
	<input type="button" class="form_button" id="idCreate" 	name="btnCreate" value="新增" onclick="create()" />
	<input type="button" class="form_button" id="idView" 	name="btnView"	 value="查看" disabled="disabled" onclick="view()" />
	<input type="button" class="form_button" id="idEdit"	name="btnEdit"	 value="修改" disabled="disabled" onclick="edit()" />
	<input type="button" class="form_button" id="idRemove" 	name="btnRemove" value="删除" disabled="disabled" onclick="remove()" />
</div>
</td></tr>
<tr valign="top" id="idGrid"><td>
<div id="gridbox" style="background-color:white;overflow:hidden;width:100%;height:300px"></div>
</td></tr>
<tr valign="top" height="24px"><td id="idPager"></td></tr>
</table>
</body>
</html>